package com.wangzh.service.impl;

import com.wangzh.dao.SMSCode;
import com.wangzh.service.ISMSCode;
import com.wangzh.utils.CodeUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.CachePut;
import org.springframework.stereotype.Service;


@Service
public class SMSCodeImpl implements ISMSCode {

    @Autowired
    private CodeUtils codeUtils;
    @Override
    @CachePut(value = "smsCode",key = "#tele")
    public String sendCodeToSMS(String tele) {
        String code = codeUtils.generator(tele);
        return code;
    }

    @Override
    public boolean checkCode(SMSCode smsCode) {
        String code = smsCode.getCode();
        String tele = smsCode.getTele();
        String cacheCode = codeUtils.getCacheCode(tele);
        return code.equals(cacheCode);
    }


}
